<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="商品编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productNo">
              <a-input v-model="model.productNo" placeholder="请输入商品编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productType">
              <a-input v-model="model.productType" placeholder="请输入商品类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="箱条码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxId">
              <a-input v-model="model.boxId" placeholder="请输入箱条码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="箱子条码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxBar">
              <a-input v-model="model.boxBar" placeholder="请输入箱子条码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input v-model="model.orderId" placeholder="请输入订单id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo">
              <a-input v-model="model.orderNo" placeholder="请输入订单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderType">
              <a-input v-model="model.orderType" placeholder="请输入订单类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productSpec">
              <a-input v-model="model.productSpec" placeholder="请输入产品规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入产品名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最小产品单元产品标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productZxxsdycpbs">
              <a-input v-model="model.productZxxsdycpbs" placeholder="请输入最小产品单元产品标识"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="医疗器械唯一标识编码体系名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productCpbsbmtxmc">
              <a-input v-model="model.productCpbsbmtxmc" placeholder="请输入医疗器械唯一标识编码体系名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最小销售单元中使用单元的数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productZxxsydydsl">
              <a-input-number v-model="model.productZxxsydydsl" placeholder="请输入最小销售单元中使用单元的数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="医疗注册人/备案人名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productYlqxzcrbarmc">
              <a-input v-model="model.productYlqxzcrbarmc" placeholder="请输入医疗注册人/备案人名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出库标识位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outFlag">
              <a-input v-model="model.outFlag" placeholder="请输入出库标识位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出借标识位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lendFlag">
              <a-input v-model="model.lendFlag" placeholder="请输入出借标识位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="调拨标识位  调拨一次+1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="allocationFlag">
              <a-input-number v-model="model.allocationFlag" placeholder="请输入调拨标识位  调拨一次+1" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仓库库位ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warePid">
              <a-input v-model="model.warePid" placeholder="请输入仓库库位ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仓库库区ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wareRid">
              <a-input v-model="model.wareRid" placeholder="请输入仓库库区ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属过道" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wareAid">
              <a-input v-model="model.wareAid" placeholder="请输入所属过道"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属仓库" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warehourse">
              <a-input v-model="model.warehourse" placeholder="请输入所属仓库"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'WmsProductForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/wms/wmsProduct/add",
          edit: "/wms/wmsProduct/edit",
          // queryById: "/wms/wmsProduct/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>